# 34. GPU调度

34

const readline = require('readline');
const rl = readline.createInterface({
    input: process.stdin,
    output: process.stdout,
});

let maxTasks = 0;
let taskArrLen = 0;
let taskArr = [];
let currentTasks = 0;
let time = 0;
let index = 0;
rl.on('line', function(line) {
    if (maxTasks === 0) {
        maxTasks = parseInt(line);
    } else if(taskArrLen === 0) {
        taskArrLen = parseInt(line);
    } else {
        taskArr = line.split(' ').map(Number);
    }
})

rl.on('close', () => {
    while(currentTasks !== 0 || index !== taskArr.length) {
        if (index < taskArr.length) {
            currentTasks += taskArr[index];
            index++;
        }
        currentTasks -= maxTasks;
        if (currentTask < 0) currentTask = 0;
        time++;
    }
    console.log(time);
})

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35